package com.raycloud.dao;

import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.raycloud.common.Result;
import com.raycloud.query.VersionQuery;
import com.raycloud.pojo.Version;

/**
 * @author  lvduo (lvduo940613@gmail.com)
 * @date    2017-04-27
 */

@Repository
public class VersionDAO {

	@Resource
    SqlMapClientTemplate sqlMapClientTemplate;

	public Integer addVersion(Version version) {
		return (Integer)this.sqlMapClientTemplate.insert("Version.insertVersion", version);
	}

    /**
    * 根据主键查找
    
    */
    public Version getVersionByKey(     String versionId       )  {
                Map<String, Object> params = new HashMap<String, Object>();
            params.put("versionId", versionId);
                Version result = (Version) this.sqlMapClientTemplate.queryForObject(
                "Version.getVersionByKey", params);
        return result;
    }
    /**
     * 根据主键批量查找
     * @
     */
    public  List<Version> getVersionByKeys(    List<String> versionIdList    )  {
                Map<String, Object> params = new HashMap<String, Object>();
                    params.put("keys", versionIdList);
                        return  (List<Version>)this.sqlMapClientTemplate.queryForList("Version.getVersionsByKeys", params);
    }
    /**
     * 根据主键删除
     * @return
     * @
     */
    public Integer deleteByKey(     String versionId       )  {
                Map<String, Object> params = new HashMap<String, Object>();
            params.put("versionId", versionId);
                Integer row = (Integer) this.sqlMapClientTemplate.delete("Version.deleteByKey", params);
        return row;
    }
    /**
     * 根据主键批量删除
     * @return
     * @
     */
    public Integer deleteByKeys(    List<String> versionIdList    )  {
                Map<String, Object> params = new HashMap<String, Object>();
                    params.put("keys", versionIdList);
                       
        Integer row = (Integer) this.sqlMapClientTemplate.delete("Version.deleteByKeys", params);
        return row;
    }
    /**
     * 根据主键更新
     * @return
     * @
     */
    public Integer updateVersionByKey(Version version) {
		return (Integer) this.sqlMapClientTemplate.update("Version.updateVersionByKey", version);
	}
    @SuppressWarnings("unchecked")
    public Result<Version> getVersionListWithPage(VersionQuery versionQuery){
	    Result<Version> rs = new Result<Version>();

            rs.setCount((Integer) this.sqlMapClientTemplate.queryForObject("Version.getVersionListCount",versionQuery));
            if(versionQuery.getFields()!=null&&versionQuery.getFields()!=""){
                rs.setList((List<Version>)this.sqlMapClientTemplate.queryForList("Version.getVersionListWithPageFields", versionQuery));
            }else{
                rs.setList((List<Version>)this.sqlMapClientTemplate.queryForList("Version.getVersionListWithPage", versionQuery));
            }

		return rs;
	}

    @SuppressWarnings("unchecked")
    public List<Version> getVersionList(VersionQuery versionQuery) {
    if(versionQuery.getFields()!=null&&versionQuery.getFields()!=""){
        return (List<Version>)this.sqlMapClientTemplate.queryForList("Version.getVersionListFields", versionQuery);
    }
		return (List<Version>)this.sqlMapClientTemplate.queryForList("Version.getVersionList", versionQuery);
	}


}